package com.beney.app.context;

import com.beney.service.UserService;

/**
 * 状态模式
 *
 * @author Beney
 */
public class AppContext {

    LoginState loginState = new LoginState(this);

    ListeningState listeningState = new ListeningState(this);

    AbstractState m_curState = loginState;

    public void runApp() {
        while (true)
        {
            m_curState.runState();
        }
    }

    /**
     * 切换状态，传递用户服务
     *
     * @param state   下一个目标状态
     * @param service 要使用的用户服务
     */
    public void shiftState(AbstractState state, UserService service)
    {
        this.m_curState = state;
        this.m_curState.userService = service;
    }
}
